﻿using System;
using log4net;

namespace SLS.ExClassLib.MultiThreading
{
    public static class DomainExceptionsHandler
    {
        /// <summary>
        /// Logs unhandled exceptions
        /// </summary>
        public static void Domain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            ILog logger = LogManager.GetLogger("Unhandled");
            var exception = e.ExceptionObject as Exception;

            if (exception == null)
                logger.ErrorFormat("Unhandled non-CLR exception occured ({0})", e.ExceptionObject.ToString());
            else
                logger.ErrorFormat("Domain unhandled exception of type {0} occured ({1})",
                                   e.GetType().Name, e.ExceptionObject);
        }
    }
}